package com.xyebank.ledger.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.modelmapper.AbstractConverter;
import org.springframework.stereotype.Component;

/**
*
*
* @author rcl:
* @version 创建时间：2018年9月12日 上午11:56:07
* 
*/
@Component
public class DateConverter extends AbstractConverter<String, Date>{

    @Override
    protected Date convert(String source) {
        Date result = null;
        if (StringUtils.isEmpty(source)){
            return result;
        }
        try {
            result = DateUtil.str2Date(source, "yyyy-MM-dd HH:mm:ss");
            
        } catch (Exception e) {
            try {
                result = DateUtil.str2Date(source, "yyyyMMddHHmmss");
            } catch (ParseException e1) {
                System.out.println(e1.getMessage());
                e1.printStackTrace();
            }
        }
        return result;
    }

    public DateConverter() {
        // TODO Auto-generated constructor stub
    }
    
    public static void main(String[] args) throws ParseException{
        Date str = new DateConverter().convert("20180109161821");
        System.out.println(str);
    }
}
